package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IDisputeDealView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *矛盾纠纷办理
 */
public class DisputeDealPest {

    private IDisputeDealView iDisputeDealView;

    public DisputeDealPest(IDisputeDealView iDisputeDealView) {
        this.iDisputeDealView=iDisputeDealView;
    }

    /**
     *  办理/回退
     * @param url 处理类型url
     * @param issueStepId 事件步骤主键
     * @param content 办理意见
     * @param files 附件信息
     */
    public void disputeDeal(String url, String issueStepId , String content , List<String> files){
        disputeDeal(url,issueStepId,"",true,"","","",content,files);
    }

    /**
     *  上报
     *  @param url 处理类型url
     * @param issueStepId 事件步骤主键
     * @param targeOrg 主办单位主键
     * @param tellOrgIds 抄告单位
     * @param content 办理意见
     * @param files 附件信息
     */
    public void disputeDeal(String url, String issueStepId , String targeOrg,
                            String tellOrgIds,String content,List<String> files){
        disputeDeal(url,issueStepId,"",targeOrg,tellOrgIds,content,files);
    }

    /**
     *    交办
     * @param url 处理类型url
     * @param issueStepId 事件步骤主键
     * @param dealDeadline 截止时间
     * @param targeOrg 主办单位主键
     * @param tellOrgIds 抄告单位
     * @param content 办理意见
     * @param files 附件信息
     */
    public void disputeDeal(String url, String issueStepId , String dealDeadline , String targeOrg,
                            String tellOrgIds,String content,List<String> files){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("issueStepId", issueStepId);
        map.put("logNew.dealDeadline",dealDeadline);
        map.put("logNew.targeOrg.id",targeOrg);
        map.put("tellOrgIds",tellOrgIds);
        map.put("logNew.content",content);
        if (files!=null&&files.size()>0){
            for (int i=0;i<files.size();i++){
                map.put("logNew.files["+i+"].path",files.get(i));
            }
        }
        new ApiManager().disputeDeal(url,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                iDisputeDealView.showMes("事件处理成功");
            }
            @Override
            public void onFailures(String message) {
                iDisputeDealView.showError(message);
            }
        });
    }


    /**
     * 办结
     * @param url 处理类型url
     * @param issueStepId 事件步骤主键
     * @param time 化解时限
     * @param isSuccess 化解是否成功
     * @param dealWay 化解方式
     * @param statue 化解情况
     * @param followWork 后续工作措施
     * @param content 调处情况
     * @param files 附件信息
     */
    public void disputeDeal(String url, String issueStepId , String time ,boolean isSuccess,
                           String dealWay,String statue,String followWork,
                            String content,List<String> files){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("issueStepId", issueStepId);
        map.put("issue.handleTime",time);
        map.put("issue.handleSuccessed",isSuccess);
        map.put("issue.resolvingWay.id",dealWay);
        map.put("issue.resolveSituation.id",statue);
        map.put("issue.followWork",followWork);
        map.put("logNew.content",content);
        if (files!=null&&files.size()>0){
            for (int i=0;i<files.size();i++){
                map.put("logNew.files["+i+"].path",files.get(i));
            }
        }
        new ApiManager().disputeDeal(url,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                iDisputeDealView.showMes("事件处理成功");
            }
            @Override
            public void onFailures(String message) {
                iDisputeDealView.showError(message);
            }
        });
    }

}
